<?php

namespace app\mec\controller;
use think\Db;
use app\admin\model\UserModel;
use app\admin\model\UserType;
use think\Session;

class Four extends Base
{

    /**
     * [index 用户列表]
     * @return [type] [description]
     * @author
     */
    public function index(){
        if(request()->isAjax ()){
            extract(input());
            $map = [];
            $fids = $this->getSonIDS();
            $map['info_fen_id'] = ['in',$fids];
            if(isset($key)&&$key!="")
            {
                $map['order_num|fen_realname'] = ['like',"%" . $key . "%"];
            }
            if(isset($level)&&$level!="")
            {
                $map['info_level'] = $level;
            }
            if(isset($shi)&&$shi!="")
            {
                $map['order_shi'] = $shi;
            }
//
            if(isset($start)&&$start!=""&&isset($end)&&$end=="")
            {
                $map['info_time'] = ['>= time',$start];
            }
            if(isset($end)&&$end!=""&&isset($start)&&$start=="")
            {
                $map['info_time'] = ['<= time',$end];
            }
            if(isset($start)&&$start!=""&&isset($end)&&$end!="")
            {
                $map['info_time'] = ['between time',[$start,$end]];
            }
            if(isset($way)&&$way!="")
            {
                $map['a.order_way'] = $way;
            }

            $Nowpage = input('page') ? input('page'):1;
            $limits = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::table('up_order_info')->alias('s')
                ->join('up_order a','s.info_order_id=a.order_id','LEFT')
                ->join('up_area area','a.order_shi=area.district_id','LEFT')
                ->join('up_fenxiao f','s.info_fen_id=f.fen_id','LEFT')
                ->where($map)
                ->count();
            $lists = Db::table('up_order_info')->alias('s')
                ->join('up_order a','s.info_order_id=a.order_id','LEFT')
                ->join('up_area area','a.order_shi=area.district_id','LEFT')
                ->join('up_fenxiao f','s.info_fen_id=f.fen_id','LEFT')
                ->where($map)
                ->order('info_id desc')
                ->page($Nowpage, $limits)
                ->field('s.*,fen_id,fen_realname,district,order_num,order_money,order_fourmoney,order_way')
                ->select();//计算总页面
            $count2 = Db::table('up_order_info')->alias('s')
                ->join('up_order a','s.info_order_id=a.order_id','LEFT')
                ->join('up_area area','a.order_shi=area.district_id','LEFT')
                ->join('up_fenxiao f','s.info_fen_id=f.fen_id','LEFT')
                ->where($map)
                ->order('info_id desc')
                ->sum('info_money');
            return json(['code'=>220,'msg'=>'','count'=>$count,'data'=>$lists,'count2'=>$count2]);
        }
        $citys = Db::table('up_area')->where('level',2)->select();
        $this->assign('citys',$citys);
        $level = Db::name('fenxiao')->where('fen_id',session('mid'))->value('fen_level');
        $this->assign('ll',$level);
        return $this->fetch("four/index");
    }


}